<template>
	<view class="">
		<search></search>
		<view>
			<swiper class="" indicator-dots="true" autoplay="true" circular="true" interval="2000">
				<swiper-item v-for="(item, index) in banners" :key="index"><image :src="item.imageUrl" mode="widthFix" lazy-load="true" binderror="" bindload="" /></swiper-item>
			</swiper>
		</view>
		<view class="tabcrtol">
			<view class="tabitem">
				<navigator class="" target="" url="../listsquare/listsquare" hover-class="navigator-hover" open-type="navigate">
					<view class="imgbox"><image class="" src="../../static/list1.png" mode="widthFix" lazy-load="true" binderror="" bindload="" /></view>
					<view class="name">歌单</view>
				</navigator>
			</view>
			<view class="tabitem">
				<navigator class="" target="" url="../rankinglist/rankinglist" hover-class="navigator-hover" open-type="navigate">
					<view class="imgbox"><image class="" src="../../static/rank.png" mode="widthFix" lazy-load="false" binderror="" bindload="" /></view>
					<view class="name">排行</view>
				</navigator>
			</view>
			<view class="tabitem">
				<navigator class="" target="" url="../mvsquare/mvsquare" hover-class="navigator-hover" open-type="navigate">
					<view class="imgbox"><image class="mv" src="../../static/MV.png" mode="widthFix" lazy-load="false" binderror="" bindload="" /></view>
					<view class="name">MV</view>
				</navigator>
			</view>
			<view class="tabitem">
				<navigator class="" target="" url="../singersquare/singersquare" hover-class="navigator-hover" open-type="navigate">
					<view class="imgbox"><image class="songer" src="../../static/songer1.png" mode="widthFix" lazy-load="false" binderror="" bindload="" /></view>
					<view class="name">歌手</view>
				</navigator>
			</view>
			<view class="tabitem">
				<navigator target="" url="">
					<view class="imgbox"><image class="radio" src="../../static/radio1.png" mode="widthFix" lazy-load="false" binderror="" bindload="" /></view>
					<view class="name">电台</view>
				</navigator>
			</view>
		</view>

		<view class="newmusic">
			<view class="title">新歌速递</view>
			<view class="musicbox">
				<view class="musicitem" v-for="(item, index) in newSong" :key="item.id" @click="playMusic(item.id)">
					<view class="songimg"><image class="" lazy-load="true" :src="item.picUrl" mode="widthFix" /></view>
					<view class="titlename">
						<view class="musictitle">{{ item.name }}</view>
						<view class="musicsinger">{{ item.author }}</view>
					</view>
					<view class="playicon"><image class="" lazy-load="true" src="../../static/play1.png" mode="widthFix" /></view>
				</view>
			</view>
		</view>

		<view class="singer">
			<view class="singertitle">热门歌手</view>
			<view class="singerbox">
				<view class="singeritem" v-for="(item, index) in singer" :key="index" @click="gotoSinger(item)">
					<view class="singerimage"><image class="" :src="item.picUrl" mode="widthFix" lazy-load="true" binderror="" bindload="" /></view>
					<view class="singername">{{ item.name }}</view>
				</view>
			</view>
		</view>

		<view class="playlist">
			<view class="playlisttitle">推荐歌单</view>
			<view class="playlistbox">
				<view class="playlistitem" v-for="(item, index) in playlist" :key="index">
					<view class="" @click="goPlayList(item.id)">
						<view class="playlistimg">
							<image class="" :src="item.picUrl" mode="widthFix" />
							<view class="playlistcount">
								<image src="../../static/play2.png" mode="widthFix" lazy-load="true"></image>
								<view class="tricontent">{{ item.newPlayCount }}</view>
							</view>
						</view>
						<view class="playlistname">{{ item.name }}</view>
					</view>
				</view>
			</view>
		</view>

		<view class="mv">
			<view class="mvtitle">推荐mv</view>
			<view class="mvbox">
				<view class="mvitem" v-for="(item, index) in mvs" :key="index">
					<view class="mvimg" @click="gotoMv(item.id,item.type)">
						<view class="bgimgbox"><image class="" src="../../static/play1.png" mode="widthFix" lazy-load="false" /></view>
						<image class="" :src="item.picUrl" mode="widthFix" lazy-load="true" />
					</view>
					<view class="mvname">{{ item.name }}</view>
					<view class="mvcount">播放量：{{ item.playCount }}</view>
				</view>
			</view>
		</view>
		<mytarbar class="mytarbar"></mytarbar>
	</view>
</template>

<script>
import Search from '../../components/search/search.vue';
import MyTarBar from '../../components/mytarbar/mytarbar.vue';
import { HomeRequest } from '../../api/home.js';

export default {
	data() {
		return {
			banners: [],
			newSong: [],
			singer: [],
			playlist: [],
			mvs: [],
			song: {
				name: '暂未播放歌曲',
				picUrl: '../../static/1yemeng.jpg',
				author: '未知'
			}
		};
	},
	comments: {
		Search,
		MyTarBar
	},

	onLoad() {
		this.getBanner();
		this.getNewSong();
		this.getArtists();
		this.gePlaylist();
		this.getMvs();
	},
	methods: {
		async getBanner() {
			let result = await HomeRequest({
				url: '/banner'
			});
			this.banners = result[1].data.banners;
		},
		async getNewSong() {
			let result = await HomeRequest({
				url: '/personalized/newsong'
			});
			this.newSong = result[1].data.result;
		},
		async getArtists() {
			let result = await HomeRequest({
				url: '/top/artists',
				data: {
					offset: 0,
					limit: 8
				}
			});
			this.singer = result[1].data.artists;
		},
		async gePlaylist() {
			let result = await HomeRequest({
				url: '/personalized',
				data: {
					limit: 6
				}
			});
			let playlist = result[1].data.result.map(item => {
				if (item.playCount / 10000 >= 10000) {
					item.newPlayCount = Math.round(item.playCount / 10000 / 10000) + '亿';
				} else {
					item.newPlayCount = Math.round(item.playCount / 10000) + '万';
				}
				return item;
			});
			this.playlist = playlist;
		},
		async getMvs() {
			let result = await HomeRequest({
				url: '/personalized/mv'
			});
			let mvs = result[1].data.result;
			this.mvs = mvs;
		},

		playMusic(id) {
			// uni.navigateTo({
			// 	url: '/pages/music/music?id=' + id
			// });
			this.$store.dispatch('getSong', id);
		},
		goPlayList(id) {
			uni.navigateTo({
				url: '/pages/playlist/playlist?id=' + id
			});
		},
		gotoSinger(singer){
			uni.navigateTo({
				url: '/pages/singer/singer?id='+singer.id 
			});
			// uni.$emit("getsinger",singer)
			uni.setStorageSync("singer",singer);
		},
		gotoMv(id,type){
			uni.navigateTo({
				url: '/pages/mv/mv?id='+id+"&type="+type 
			});
		}
	}
};
</script>

<style lang="scss" scoped>
/* pages/home/home.wxss */
page {
	padding-bottom: 130upx;
}

swiper {
	width: 750upx;
	height: 290upx;
}

swiper image {
	width: 100%;
	height: auto;
}

.tarbar {
	position: fixed;
	bottom: 0upx;
	left: 0upx;
	right: 0upx;
}

.tabcrtol {
	display: flex;
	height: 160upx;
	margin-top: 20upx;
}

.tabcrtol .tabitem {
	flex: 1;
	position: relative;
}

.tabcrtol .tabitem navigator {
	width: 100%;
	height: 120upx;
	margin-top: 0;
	text-align: center;
	position: absolute;
	top: 0;
}

.tabcrtol .tabitem navigator .imgbox {
	position: absolute;
	top: 0;
	left: 50%;
	transform: translate(-50%);
	height: 90upx;
	width: 90upx;
	background: $uni-bg-color;
	border-radius: 50%;
	display: flex;
	justify-content: center;
	align-items: center;
}

.tabcrtol .tabitem navigator .imgbox image {
	margin: 0;
	width: 70%;
	height: auto;
}

.tabcrtol .tabitem navigator .imgbox .mv,
.tabcrtol .tabitem navigator .imgbox .songer {
	width: 60%;
	height: auto;
}

.tabcrtol .tabitem navigator .imgbox .radio {
	width: 60%;
	height: auto;
}

.tabcrtol .tabitem navigator .name {
	margin-top: 100upx;
	font-size: 30upx;
}

.newmusic {
	margin-top: 20upx;
}

.newmusic .title {
	padding: 20upx;
	font-size: 36upx;
	margin-bottom: 20upx;
	font-weight: bold;
}

.newmusic .musicitem {
	margin-bottom: 20upx;
	height: 120upx;
	display: flex;
}

.newmusic .musicitem .songimg {
	flex: 2;
	width: 120upx;
	overflow: hidden;
}

.newmusic .musicitem .songimg image {
	margin-left: 20upx;
	width: 120upx;
	height: auto;
	border-radius: 20upx;
}

.newmusic .musicitem .titlename {
	flex: 4;
	height: 120upx;
	font-size: 26upx;
}

.newmusic .musicitem .titlename view {
	height: 60upx;
	line-height: 60upx;
}

.newmusic .musicitem .titlename .musictitle {
	font-size: 32upx;
}

.newmusic .musicitem .titlename .musicsinger {
	color: #ccc;
}

.newmusic .musicitem .playicon {
	flex: 1;
	height: 100%;
	overflow: hidden;
}

.newmusic .musicitem .playicon image {
	width: 60upx;
	height: auto;
	margin-top: 20upx;
	margin-left: 30upx;
}

.singer .singertitle {
	padding: 20upx;
	font-size: 36upx;
	font-weight: bold;
}

.singer .singerbox {
	display: flex;
	flex-wrap: wrap;
}

.singer .singerbox .singeritem {
	width: 25%;
	margin-top: 30upx;
}

.singer .singerbox .singeritem .singerimage {
	height: 130upx;
	overflow: hidden;
}

.singer .singerbox .singeritem .singerimage image {
	width: 80%;
	height: auto;
	margin-left: 10%;
	border-radius: 10upx;
}

.singer .singerbox .singeritem .singername {
	font-size: 26upx;
	width: 100%;
	text-align: center;
}

.playlist .playlisttitle {
	padding: 20upx;
	font-size: 36upx;
	margin: 20upx 0upx;
	font-weight: bold;
}

.playlist .playlistbox {
	display: flex;
	flex-wrap: wrap;
}

.playlist .playlistbox .playlistitem {
	width: 33.33%;
}

.playlist .playlistbox .playlistitem .playlistimg {
	width: 90%;
	position: relative;
}

.playlist .playlistbox .playlistitem .playlistimg image {
	width: 100%;
	margin-left: 5%;
	border-radius: 10upx;
	height: auto;
}

.playlist .playlistbox .playlistitem .playlistimg .playlistcount {
	width: 100%;
	position: absolute;
	top: 10upx;
	right: 10upx;
	color: white;
	text-align: right;
	vertical-align: middle;
}

.playlist .playlistbox .playlistitem .playlistimg .playlistcount image {
	width: 25upx;
	height: auto;
	vertical-align: middle;
	display: inline-block;
}

.playlist .playlistbox .playlistitem .playlistimg .playlistcount .tricontent {
	font-size: 22upx;
	display: inline-block;
	vertical-align: middle;
}

.playlist .playlistbox .playlistitem .playlistname {
	font-size: 26upx;
	margin: 0px 20upx 20upx 20upx;
	display: -webkit-box;
	-webkit-box-orient: vertical;
	-webkit-line-clamp: 2;
	overflow: hidden;
}

.mv .mvtitle {
	padding: 20upx;
	font-size: 36upx;
	margin: 20upx 0upx;
	font-weight: bold;
}

.mv .mvbox {
	display: flex;
	flex-wrap: wrap;
}

.mv .mvbox .mvitem {
	width: 50%;
	margin-bottom: 20upx;
}

.mv .mvbox .mvitem  .mvimg {
	width: 96%;
	overflow: hidden;
	position: relative;
	margin: 0 2%;
}

.mv .mvbox .mvitem  .mvimg image {
	width: 100%;
	height: auto;
}

.mv .mvbox .mvitem  .mvimg .bgimgbox {
	position: absolute;
	top: 0;
	left: 0;
	right: 0;
	bottom: 0;
	display: flex;
	justify-content: center;
	align-items: center;
}

.mv .mvbox .mvitem  .mvimg .bgimgbox image {
	width: 100upx;
	height: auto;
}

.mv .mvbox .mvitem .mvname {
	height: 40upx;
	line-height: 40upx;
	margin: 0upx 20upx;
	display: -webkit-box;
	-webkit-box-orient: vertical;
	-webkit-line-clamp: 1;
	overflow: hidden;
	font-size: 26upx;
}

.mv .mvbox .mvitem .mvcount {
	margin: 10upx 20upx;
	font-size: 25upx;
	color: #ccc;
}

.mytarbar {
	position: fixed;
	bottom: 0;
	left: 0;
	right: 0;
}
</style>
